<html>
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="Xadmin/css/xadmin.css">
    <link rel="stylesheet" href="Xadmin/css/font.css">
    <link rel="stylesheet" href="Xadmin/css/login.css">
    <script src="Xadmin/js/xadmin.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script src="layui/layui.js" charset="Utf-8"></script>
    <script src="JS/Tool.js" charset="Utf-8"></script>
</head>
<body style="background-image: url('Img/bjt.jpg') ;background-size: 100% 100%; background-repeat: no-repeat;min-height: 0 ">
<div class="login" style="margin-left: 80rem;margin-top: 12rem">
    <div class="message">后台登录</div>
    <form method="post" style="margin-top: 2rem">
        <input name="userName" placeholder="用户名" class="layui-input" id="userName">
        <hr class="hr15">
        <input name="passWord" placeholder="密码" class="layui-input" type="password" id="passWord">
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width: 100%;" type="button" onclick="login()">
    </form>
    <p style="color: red">如多次登录失败，请联系管理员！</p>
</div>

</body>
<script>
    var layer
    layui.use('layer',function () {//引入 layui的组件
        layer = layui.layer
    })
    function login(){//登录方法
        $.ajax({//ajax请求数据
            url:baseUrl+"v2/User/login",//请求的借口
            type:"post",//请求方法
            data:{//向后端传送的数据
                username:$("#userName").val(),//根据id号获取值，
                password:$("#passWord").val()
            },
            success:function (res){//成功的回调函数
                var object = JSON.parse(res)
                localStorage.setItem("login_token",object.msg);
                localStorage.setItem("menuList",JSON.stringify(object.data))
                if(object.code===0){
                    localStorage.setItem("uName",$("#userName").val())
                    layer.alert("登录成功！，即将跳转")
                    window.location.href="index.html"
                }else{
                    layer.alert("登录失败！，请重新尝试!")
                }
            },
            error:function (e){//失败的回调函数
                layer.alert("请求失败"+e.responseText)
            }
        })
    }
</script>
</html>
